package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.*;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StockServiceImpl implements StockService {
    @Autowired
    private DamageListDao damageListDao;
    @Autowired
    private DamageListGoodsDao damageListGoodsDao;
    @Autowired
    private OverflowListGoodsDao overflowListGoodsDao;
    @Autowired
    private OverflowListDao overflowListDao;

    @Autowired
    private GoodsDao goodsDao;

    @Override
    @Transactional
    public void saveDamageListGoods(DamageList damageList, List<DamageListGoods> goodsList) {
        damageListDao.insert(damageList);

        Integer damageListId = damageList.getDamageListId();

        damageListGoodsDao.insertAll(goodsList,damageListId);


    }

    @Override
    @Transactional
    public void saveOverflowListGoods(OverflowList overflowList, List<OverflowListGoods> goodsList) {
        overflowListDao.insert(overflowList);

        Integer overflowListId = overflowList.getOverflowListId();

        overflowListGoodsDao.insertAll(goodsList,overflowListId);
    }

    @Override
    public List<Goods> listAlarmGoods() {

        return goodsDao.listAlarmGoods();
    }

    @Override
    public List<DamageList> getDamageListList(String sTime, String eTime) {
        return damageListDao.findByTime(sTime,eTime);

    }

    @Override
    public List<OverflowList> getOverflowListList(String sTime, String eTime) {
        return overflowListDao.findByTime(sTime,eTime);
    }

    @Override
    public List<DamageListGoods> getDamageListGoods(Integer damageListId) {
        return damageListGoodsDao.listById(damageListId);
    }

    @Override
    public List<OverflowListGoods> getOverflowListGoods(Integer overflowListId) {
        return overflowListGoodsDao.listById(overflowListId);
    }
}
